//------------------------------------------------------------------------------ 
//      Copyright (c) 2004, Be Nanashi-San 
// 
//      Permission is hereby granted, free of charge, to any person obtaining a 
//      copy of this software and associated documentation files (the "Software"), 
//      to deal in the Software without restriction, including without limitation 
//      the rights to use, copy, modify, merge, publish, distribute, sublicense, 
//      and/or sell copies of the Software, and to permit persons to whom the 
//      Software is furnished to do so, subject to the following conditions: 
// 
//      The above copyright notice and this permission notice shall be included in 
//      all copies or substantial portions of the Software. 
// 
//      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
//      IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
//      FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
//      AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
//      LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
//      FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
//      DEALINGS IN THE SOFTWARE. 
// 
//      File Name:	NetUtil.h
//      Author: 	Be Nanashi-San 
//      Description:	 
//------------------------------------------------------------------------------

#ifndef NETUTIL_H_INCLUDED
#define NETUTIL_H_INCLUDED
#include <String.h>

// HTTP status
const int HTTP_OK = 200;
const int HTTP_PARTIAL_CONTENT = 206;
const int HTTP_NOT_MODIFIED = 304;
const int HTTP_RANGE_NOT_SATISFIABLE = 416;

//20051114:メンバrange削除。
//20051210:res_start追加。
struct http_info{
	int status;
	int header_length;
	int body_length;
	bool gzipped;
	BString modified;
	int res_start; //まちBBS差分取得用

	void init(bool gzipped){
		status = 0;
		header_length = 0;
		body_length = 0;
		gzipped = gzipped;
		modified = "";
		res_start = 0;
 	}
};

class BMallocIO;

int get(const char *uri, const char *filename, BMallocIO &outbuf, http_info &info);
int matchbbsthreadget(const char *uri, const char *filename, BMallocIO &outbuf, http_info &info);
void uri2host(const char *uri, char *host, char* subdir = NULL);
status_t getData(const char *requestheader, const char *host, BMallocIO &nbuf);
void Urlescape(const char *in, BString &out);

#endif //NETUTIL_H_INCLUDED
